﻿using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using Xceed.Wpf.AvalonDock.Layout;
using Xceed.Wpf.AvalonDock;

namespace AvalonDockDemo
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void LayoutPanel_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;

            var contextMenu = new ContextMenu();

            var horizontalItem = new MenuItem { Header = "水平分割" };
            horizontalItem.Click += (s, args) => PerformSplit("Horizontal");

            var verticalItem = new MenuItem { Header = "垂直分割" };
            verticalItem.Click += (s, args) => PerformSplit("Vertical");

            contextMenu.Items.Add(horizontalItem);
            contextMenu.Items.Add(verticalItem);

            contextMenu.IsOpen = true;
        }

        private void PerformSplit(string orientation)
        {
            if (orientation == "Horizontal")
            {
                MessageBox.Show("执行水平分割操作");
                var layoutPanel = new LayoutPanel { Orientation = Orientation.Horizontal };
                var leftPane = new LayoutAnchorablePane();
                leftPane.Children.Add(new LayoutAnchorable { Title = "左侧分割面板" });

                var rightPane = new LayoutDocumentPane();
                rightPane.Children.Add(new LayoutDocument { Title = "右侧文档示例" });

                layoutPanel.Children.Add(leftPane);
                layoutPanel.Children.Add(rightPane);

                
            }
            else if (orientation == "Vertical")
            {
                MessageBox.Show("执行垂直分割操作");
                var layoutPanel = new LayoutPanel { Orientation = Orientation.Vertical };

                var topPane = new LayoutDocumentPane();
                topPane.Children.Add(new LayoutDocument { Title = "顶部区域示例" });

                var bottomPane = new LayoutAnchorablePane();
                bottomPane.Children.Add(new LayoutAnchorable { Title = "底部区域示例" });

                layoutPanel.Children.Add(topPane);
                layoutPanel.Children.Add(bottomPane);

                
            }
        }
    }
}
